<?php

/**
 * 
 * Sun CMS
 * 
 * @author			Burning
 * @copyright		Copyright (c) 2009, IsunCms.Com.
 * @license			http://www.isuncms.com/license.htm
 * @link				http://www.isuncms.com/
 * @since				Version 1.0 Beta
 * 
 */

require_once( dirname( strtr(__FILE__, '\\', '/') ).'/include/common.inc.php' );

$file = get_post( 'file' );

$referer = empty( $referer )?SITE_URL:$referer;

if( empty( $file ) )
{
	jump( "SunCMS提示：请选择需要下载的文件！", $referer, 3 );
	exit;
}

$file = authcode( $file );

$file_info = $db->get_one( DB_PRE.'enclosure', array( 'name' => $file ) );

if( !$file_info )
{
	jump( "SunCMS提示：文件地址已失效！", $referer, 5 );
	exit;
}

$file_full_name = $file_info['name'].'.'.$file_info['type'];
$datas = file_get_contents( SUNCMS.'uploads/enclosure/'.$file_full_name );

if( $file_info['encrypt'] )
{
	$slogin = get_cookie( 'slogin' );
	if( $slogin )
	{
		downloads( $file_full_name, $datas );
	}
	else 
	{
		jump( '请先登录后进行相关操作！', SITE_URL.'login.php', 3 );
	}
}
else 
{
	downloads( $file_full_name, $datas );
}